/*
 * BasicStitching.cpp
 *
 *  Created on: Mar 1, 2013
 *      Author: RDU
 */

#include "basicstitching.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/stitching/stitcher.hpp"

BasicStitching::BasicStitching()
{
	try_use_gpu=false;
}

BasicStitching::~BasicStitching()
{

}

void BasicStitching::LoadImages()
{
	//Read images from files
//	Mat leftImage=imread("left.jpg");
//	Mat middleImage=imread("middle.jpg");
//	Mat rightImage=imread("right.jpg");

//	Mat leftImage=imread("image0.jpg");
//	Mat middleImage=imread("image1.jpg");
//	Mat rightImage=imread("image2.jpg");

	Mat leftImage=imread("image121-0.jpg");
	Mat middleImage=imread("image121-1.jpg");
	Mat rightImage=imread("image121-2.jpg");

	m_cvImages.push_back(leftImage);
	m_cvImages.push_back(middleImage);
	m_cvImages.push_back(rightImage);
}

void BasicStitching::StitchImages()
{
	//Stitch images
	LoadImages();

	Stitcher stitcher=Stitcher::createDefault(try_use_gpu);
	Stitcher::Status status=stitcher.stitch(m_cvImages,m_stitchedImage);

	if(status != Stitcher::OK)
	{
		//String str;
		//str="Can't stitch images, error code = "+int(status);

		wxMessageBox(wxT("Can't stitch images."));

		return;
	}

	imwrite("result.jpg",m_stitchedImage);
}

Mat BasicStitching::GetStitchedImage()
{
	StitchImages();

	return m_stitchedImage;
}
